package com.wlcj.www.model.product;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.jfinal.plugin.activerecord.Model;



public class Product extends Model<Product>{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 4423731976792219304L;
	public static final Product dao = new Product();
	/**
	 * 最新标的
	 */
	public List<Product> getNewProduct(){
		String sql = "select a.*,b.logo from wd_p_product a  left join wd_p_img b  on a.platform_id = b.platform_id order by a.product_id desc limit 0,7 ";
		return find(sql);
	}
	
	/**
	 * 按收益选标
	 * @return
	 */
	public List<Product> getProduct(){
		String sql = "select a.*,b.logo from wd_p_product a  left join wd_p_img b  on a.platform_id = b.platform_id order by a.complete_percentage desc limit 0,3 ";
		return find(sql);
	}
	/**
	 * 人气产品和推荐产品和限时产品和新品
	 */
	public Map<String,List<Product>> getGoodProduct(){
		Map<String,List<Product>> maps = new HashMap<String, List<Product>>();
		String sql1 = "select a.*,b.logo,c.platform_name from wd_p_product a  left join wd_p_img b  on a.platform_id = b.platform_id,wd_p_platform c where 80<=complete_percentage and complete_percentage<=99 and a.platform_id=c.platform_id order by a.complete_percentage asc  limit 0,1  ";//人气
		String sql2 = "select a.*,b.logo,c.platform_name from wd_p_product a  left join wd_p_img b  on a.platform_id = b.platform_id,wd_p_platform c where 10<=complete_percentage and complete_percentage<=60 and a.platform_id=c.platform_id order by a.complete_percentage asc  limit 0,1   ";//新品
		String sql3 = "select a.*,b.logo,c.platform_name from wd_p_product a  left join wd_p_img b  on a.platform_id = b.platform_id,wd_p_platform c where 90<=complete_percentage and complete_percentage<=99 and a.platform_id=c.platform_id order by a.complete_percentage asc  limit 0,1";//限时
		String sql4 = "select a.*,b.logo,c.platform_name from wd_p_product a  left join wd_p_img b  on a.platform_id = b.platform_id,wd_p_platform c where 60<=complete_percentage and complete_percentage<=99 and a.platform_id=c.platform_id order by a.complete_percentage asc  limit 0,1";//推荐
		maps.put("renqi", find(sql1));
		maps.put("news", find(sql2));
		maps.put("xianshi", find(sql3));
		maps.put("tuijian", find(sql4));
		return maps;
	}
	/**
	 * 按期限选标（完成度高的优先展示）
	 */
	public Map<String,List<Product>> getQiXian(){
		Map<String,List<Product>> maps = new HashMap<String, List<Product>>();
		String sql1=" select * from wd_p_product  where borrow_date < 180 order by complete_percentage   desc  limit 0,3 ";//短期稳赢
		String sql2=" select * from wd_p_product  where borrow_date >= 180 and borrow_date <= 365 order by complete_percentage   desc  limit 0,3 ";//中期保收益
		String sql3=" select * from wd_p_product  where borrow_date > 365 order by complete_percentage   desc  limit 0,3 ";//长期优选
		maps.put("duan", find(sql1));
		maps.put("zhong", find(sql2));
		maps.put("chang", find(sql3));
		return maps;
	}
	/**
	 * 大家都购买了那些产品
	 */
	public List<Product> getMessageBy(){
		String sql = " select * from wd_p_product_detail a left join  wd_p_product b on a.p_product_id=b.product_id order by product_detail_id desc limit 0,30";
		return find(sql);
	}


}
